package com.gklyj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gklyj.pojo.User;
import com.gklyj.pojo.Zhanghao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface userMapper extends BaseMapper<User> {

    @Select("select u_id from user where name=#{name} and phone_number=#{phone_number}")
    Integer findIdByName_Phone(String name,String phone_number);

    //根据账号获取用户姓名，用于登录显示 xxxx欢迎你
    @Select("select name from user where u_id in(select u_id from user_zhanghao where z_id in (select z_id from zhanghao where username = #{username})) ")
    String findNameByUsername(String username);

    //根据账号获取招聘单位的部门
    @Select("select department from user where u_id in(select u_id from user_zhanghao where z_id in (select z_id from zhanghao where username = #{username})) ")
    String findDepartmentByUsername(String username);

    //获取不同角色的全部用户信息，用于管理员的求职者信息管理或招聘单位信息管理
    @Select("select * from user where u_id in(select u_id from user_zhanghao where z_id in (select z_id from zhanghao where role = #{role}))")
    List<User> findUserByRole(String role);

    //求职者 信息管理页面的查询操作,使用mapper
//    @Select("select * from user where name=#{name} and grade=#{grade} and" +
//            "stu_id=#{stu_id} and u_id in(select u_id from user_zhanghao where z_id in (select z_id from zhanghao where role = 'student'))")
    List<User> searchQzUser(User user);

    //    用于求职者编辑信息的数据回显
    @Select("select * from user where u_id = #{u_id}")
    User findUserById(Integer u_id);

    List<User> searchZpUser(User user);

    //根据账号获取用户信息，用于个人中心回显
    @Select("select * from user where u_id in(select u_id from user_zhanghao where z_id in (select z_id from zhanghao where username = #{username})) ")
    User findUserByUsername(String username);

    //分别求出对各年级的求职者数量
    @Select("select count(grade) from user where grade=#{grade}")
    Integer getQzNumberByGrade(String grade);

    //求所有求职者数量
    @Select("select count(*) from user where grade is not null")
    Integer getQiuzhiNumber();

    //求所有招聘单位数量
    @Select("select count(*) from user where grade is null")
    Integer getZhaopingNumber();
}
